package org.aldar.bquest.resources;

import android.content.Context;
import android.graphics.Color;
import org.aldar.bquest.constants.LandscapeType;
import org.aldar.bquest.entity.AbilityTileSprite;
import org.aldar.bquest.entity.LsTextureDef;
import org.aldar.bquest.logic.GameTutorial;
import org.aldar.bquest.logic.controller.level.LevelDefinition;
import org.aldar.bquest.profile.GameProfile;
import org.aldar.bquest.util.Logger;
import org.andengine.audio.sound.Sound;
import org.andengine.audio.sound.SoundManager;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.font.FontManager;
import org.andengine.opengl.font.IFont;
import org.andengine.opengl.texture.Texture;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.math.MathUtils;

import java.io.IOException;
import java.util.*;

/**
 * User: Daria
 * Date: 4/14/13 9:53 PM
 */
public class ResourceManager {

    protected List<Texture> mAllTextures = new LinkedList<Texture>();
    protected List<String> mAllTextureNames = new LinkedList<String>();

    protected List<Texture> afterLoadTextures = new LinkedList<Texture>();
    protected List<String> afterLoadTextureNames = new LinkedList<String>();

    private static final Logger LOG = new Logger(ResourceManager.class);


    static Map<LandscapeType, LsTextureDef[]> lsTexturesArr = new HashMap<LandscapeType, LsTextureDef[]>();

    static {
        lsTexturesArr.put(LandscapeType.TOWN,
                new LsTextureDef[]{
                        new LsTextureDef("town_1.png", 2, 52, 150, "new/tl_town_base.png", 160, 180),
                        new LsTextureDef("town_2.png", 1, 44, 150, "new/tl_town_base.png", 160, 180),
                        new LsTextureDef("town_3.png", 1, 51, 150, "new/tl_town_base.png", 160, 180),
                        new LsTextureDef("town_4.png", 1, 39, 150, "new/tl_town_base.png", 160, 180),
                        new LsTextureDef("town_size_4.png", 4, 121, 150, "new/tl_town_base.png", 160, 180)
                });
        lsTexturesArr.put(LandscapeType.DARK_FOREST,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_darkforest_01.png", 1, 41, 84, "new/tl_darkforest_base.png", 26, 13),
                        new LsTextureDef("new/tl_darkforest_02.png", 1, 31, 75, "new/tl_darkforest_base.png", 26, 13),
                        new LsTextureDef("new/tl_darkforest_03.png", 1, 42, 108, "new/tl_darkforest_base.png", 26, 13)});
        lsTexturesArr.put(LandscapeType.GRAIN,
                new LsTextureDef[]{
                        new LsTextureDef(null, 1, 0, 0, "new/tl_field_base.png", 160, 180)});
        lsTexturesArr.put(LandscapeType.ROCK,
                new LsTextureDef[]{
                        new LsTextureDef("rock_1.png", 1, 28, 150, "base_mountains.png", 47, 20),
                        new LsTextureDef("rock_2.png", 2, 59, 150, "base_mountains.png", 47, 20),
                        new LsTextureDef("rock_4.png", 4, 102, 150, "base_mountains.png", 47, 20)});
        lsTexturesArr.put(LandscapeType.ROCKS_SWAMP,
                new LsTextureDef[]{
                        new LsTextureDef("rock_1.png", 1, 28, 150, "base_mountains.png", 47, 20),
                        new LsTextureDef("rock_2.png", 2, 59, 150, "base_mountains.png", 47, 20),
                        new LsTextureDef("rock_4.png", 4, 102, 150, "base_mountains.png", 47, 20)});
        lsTexturesArr.put(LandscapeType.HILLS,
                new LsTextureDef[]{
                        new LsTextureDef("hills_1.png", 1, 27, 150, "base_hills.png", 47, 20),
                        new LsTextureDef("hills_3.png", 3, 81, 150, "base_hills.png", 47, 20),
                        new LsTextureDef("hills_5.png", 4, 114, 150, "base_hills.png", 47, 20)});
        lsTexturesArr.put(LandscapeType.TOWNADD,
                new LsTextureDef[]{
                        new LsTextureDef("town_1.png", 1, 52, 150, "base_towns.png", 47, 20)});
        lsTexturesArr.put(LandscapeType.VILLAGE,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_village_1.png", 1, 160, 180, "new/tl_village_base.png", 160, 180),
                        new LsTextureDef("new/tl_village_2.png", 2, 160, 180, "new/tl_village_base.png", 160, 180),
                        new LsTextureDef("new/tl_village_3.png", 3, 160, 180, "new/tl_village_base.png", 160, 180),
                });
        lsTexturesArr.put(LandscapeType.VILLAGE_GREY,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_villagegray_1.png", 1, 47, 67, "new/tl_villagegray_base.png", 27, 19),
                        new LsTextureDef("new/tl_villagegray_2.png", 2, 62, 74, "new/tl_villagegray_base.png", 27, 19),
                        new LsTextureDef("new/tl_villagegray_3.png", 3, 77, 87, "new/tl_villagegray_base.png", 27, 19),
                });
        lsTexturesArr.put(LandscapeType.BLOSSOM_HILLS,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_blossom_hills_1.png", 1, 160, 180, "new/tl_blossom_hills_base.png", 160, 180),
                        new LsTextureDef("new/tl_blossom_hills_3.png", 3, 160, 180, "new/tl_blossom_hills_base.png", 160, 180),
                });
        lsTexturesArr.put(LandscapeType.BLOSSOM_HILLS_MAGICLAND,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_hills_magicland_1.png", 1, 30, 27, "new/tl_blossom_hills_base.png", 160, 180),
                        new LsTextureDef("new/tl_hills_magicland_3.png", 3, 84, 35, "new/tl_blossom_hills_base.png", 160, 180),
                });
        lsTexturesArr.put(LandscapeType.BUSHES,
                new LsTextureDef[]{
                        new LsTextureDef(null, 1, 0, 0, "new/tl_bushes_base.png", 160, 180),
                });
        lsTexturesArr.put(LandscapeType.BUSHES_SWAMP,
                new LsTextureDef[]{
                        new LsTextureDef(null, 1, 0, 0, "new/tl_bushes_base.png", 160, 180),
                });
        lsTexturesArr.put(LandscapeType.APPLE_TREES,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_apple_tree_1_01.png", 1, 160, 180, "new/tl_apple_tree_base.png", 160, 180),
                        new LsTextureDef("new/tl_apple_tree_1_02.png", 1, 160, 180, "new/tl_apple_tree_base.png", 160, 180),
                        new LsTextureDef("new/tl_apple_tree_1_03.png", 1, 160, 180, "new/tl_apple_tree_base.png", 160, 180),
                });
        lsTexturesArr.put(LandscapeType.PUMPKIN,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_pumpkin_01.png", 1, 38, 53, "new/tl_pumpkin_base.png", 42, 17),
                        new LsTextureDef("new/tl_pumpkin_02.png", 1, 30, 45, "new/tl_pumpkin_base.png", 42, 17),
                        new LsTextureDef("new/tl_pumpkin_03.png", 1, 29, 39, "new/tl_pumpkin_base.png", 42, 17),
                });
        lsTexturesArr.put(LandscapeType.FORESTVILLAGE,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_forestvillage_1.png", 1, 44, 69, "new/tl_forestvillage_base.png", 33, 26),
                        new LsTextureDef("new/tl_forestvillage_2_01.png", 2, 54, 80, "new/tl_forestvillage_base.png", 33, 26),
                        new LsTextureDef("new/tl_forestvillage_2_02.png", 2, 64, 84, "new/tl_forestvillage_base.png", 33, 26),
                });
        lsTexturesArr.put(LandscapeType.DEAD_FOREST,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_deadtrees_01.png", 1, 44, 98, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_02.png", 1, 54, 103, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_03.png", 1, 44, 80, "new/tl_deadtrees_base.png", 36, 20),
                });
        lsTexturesArr.put(LandscapeType.DEAD_FOREST_MAGICLAND,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_deadtrees_01.png", 1, 44, 98, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_02.png", 1, 54, 103, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_03.png", 1, 44, 80, "new/tl_deadtrees_base.png", 36, 20),
                });
        lsTexturesArr.put(LandscapeType.CASTLE,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_castle_1_01.png", 1, 44, 136, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_1_02.png", 1, 51, 114, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_2.png", 2, 65, 141, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_3.png", 3, 99, 137, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_4.png", 4, 117, 137, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_5.png", 5, 143, 137, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_6.png", 6, 169, 137, "new/tl_castle_base.png", 48, 18),
                        new LsTextureDef("new/tl_castle_7.png", 7, 181, 137, "new/tl_castle_base.png", 48, 18),
                });
        lsTexturesArr.put(LandscapeType.OAKS,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_oaks_01.png", 1, 64, 76, "new/tl_oaks_base.png", 42, 19),
                        new LsTextureDef("new/tl_oaks_02.png", 1, 52, 73, "new/tl_oaks_base.png", 42, 19),
                        new LsTextureDef("new/tl_oaks_03.png", 1, 54, 94, "new/tl_oaks_base.png", 42, 19),
                });
        lsTexturesArr.put(LandscapeType.CEMETERY,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_cemetery_01.png", 1, 46, 62, "new/tl_cemetery_base.png", 29, 17),
                        new LsTextureDef("new/tl_cemetery_02.png", 1, 30, 63, "new/tl_cemetery_base.png", 29, 17),
                        new LsTextureDef("new/tl_cemetery_03.png", 1, 32, 45, "new/tl_cemetery_base.png", 29, 17),
                });
        lsTexturesArr.put(LandscapeType.TOWN_BLUE,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_town_blue_1.png", 1, 53, 125, "new/tl_town_blue_base.png", 34, 20),
                        new LsTextureDef("new/tl_town_blue_2.png", 2, 74, 124, "new/tl_town_blue_base.png", 34, 20),
                        new LsTextureDef("new/tl_town_blue_3.png", 3, 102, 171, "new/tl_town_blue_base.png", 34, 20),
                });
        lsTexturesArr.put(LandscapeType.TOWN_MAGICLAND,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_town_magicland_1.png", 1, 33, 85, "new/tl_town_magicland_base.png", 33, 16),
                        new LsTextureDef("new/tl_town_magicland_2.png", 2, 66, 142, "new/tl_town_magicland_base.png", 33, 16),
                        new LsTextureDef("new/tl_town_magicland_3.png", 3, 88, 150, "new/tl_town_magicland_base.png", 33, 16),
                });
        lsTexturesArr.put(LandscapeType.RUINS,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_ruins_1.png", 1, 34, 78, "new/tl_ruins_base.png", 36, 17),
                        new LsTextureDef("new/tl_ruins_2.png", 2, 58, 80, "new/tl_ruins_base.png", 36, 17),
                        new LsTextureDef("new/tl_ruins_3.png", 3, 94, 84, "new/tl_ruins_base.png", 36, 17),
                });
        lsTexturesArr.put(LandscapeType.TOWN_LAVA,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_town_lava_1.png", 1, 36, 62, "new/tl_town_lava_base.png", 34, 11),
                        new LsTextureDef("new/tl_town_lava_2_01.png", 2, 54, 79, "new/tl_town_lava_base.png", 34, 11),
                        new LsTextureDef("new/tl_town_lava_2_02.png", 2, 52, 94, "new/tl_town_lava_base.png", 34, 11),
                        new LsTextureDef("new/tl_town_lava_2_03.png", 2, 52, 75, "new/tl_town_lava_base.png", 34, 11),
                });
        lsTexturesArr.put(LandscapeType.IDOL,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_idol_01.png", 1, 36, 47, "new/tl_idol_base.png", 34, 13),
                        new LsTextureDef("new/tl_idol_02.png", 2, 42, 63, "new/tl_idol_base.png", 34, 13),
                        new LsTextureDef("new/tl_idol_03.png", 3, 38, 69, "new/tl_idol_base.png", 34, 13),
                });

        lsTexturesArr.put(LandscapeType.DARK_ROCKS,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_darkrocks_1.png", 1, 40, 53, "new/tl_darkrocks_base.png", 40, 12),
                        new LsTextureDef("new/tl_darkrocks_2.png", 2, 64, 90, "new/tl_darkrocks_base.png", 40, 12),
                        new LsTextureDef("new/tl_darkrocks_3.png", 3, 92, 86, "new/tl_darkrocks_base.png", 40, 12),
                });

        lsTexturesArr.put(LandscapeType.CRATER,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_crater_1.png", 1, 42, 50, "new/tl_crater_base.png", 38, 12),
                        new LsTextureDef("new/tl_crater_2.png", 2, 66, 59, "new/tl_crater_base.png", 38, 12),
                        new LsTextureDef("new/tl_crater_3.png", 3, 92, 74, "new/tl_crater_base.png", 38, 12),
                });

        lsTexturesArr.put(LandscapeType.DEAD_FOREST_LAVA,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_deadtrees_01.png", 1, 44, 98, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_02.png", 1, 54, 103, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_03.png", 1, 44, 80, "new/tl_deadtrees_base.png", 36, 20),
                });
        lsTexturesArr.put(LandscapeType.DEAD_FOREST_SWAMP,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_deadtrees_01.png", 1, 44, 98, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_02.png", 1, 54, 103, "new/tl_deadtrees_base.png", 36, 20),
                        new LsTextureDef("new/tl_deadtrees_03.png", 1, 44, 80, "new/tl_deadtrees_base.png", 36, 20),
                });
        lsTexturesArr.put(LandscapeType.LILLY,
                new LsTextureDef[]{
                        new LsTextureDef(null, 1, 0, 0, "new/tl_lilly_01.png", 46, 23),
                        new LsTextureDef(null, 1, 0, 0, "new/tl_lilly_02.png", 44, 26),
                });
        lsTexturesArr.put(LandscapeType.CANE,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_cane_01.png", 1, 34, 92, "new/tl_cane_base.png", 48, 35),
                        new LsTextureDef("new/tl_cane_02.png", 1, 32, 86, "new/tl_cane_base.png", 48, 35),
                        new LsTextureDef("new/tl_cane_03.png", 1, 38, 69, "new/tl_cane_base.png", 48, 35),
                });
        lsTexturesArr.put(LandscapeType.VILLAGE_SWAMP,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_village_swamp_1.png", 1, 58, 102, "new/tl_village_swamp_base.png", 46, 19),
                        new LsTextureDef("new/tl_village_swamp_2.png", 2, 58, 91, "new/tl_village_swamp_base.png", 46, 19),
                        new LsTextureDef("new/tl_village_swamp_3.png", 3, 90, 98, "new/tl_village_swamp_base.png", 46, 19),
                });

        lsTexturesArr.put(LandscapeType.IDOL_MAGICLAND,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_idol_magicland_1.png", 1, 32, 43, "new/tl_idol_magicland_base.png", 36, 14),
                        new LsTextureDef("new/tl_idol_magicland_2.png", 2, 49, 75, "new/tl_idol_magicland_base.png", 36, 14),
                        new LsTextureDef("new/tl_idol_magicland_3.png", 3, 72, 86, "new/tl_idol_magicland_base.png", 36, 14),
                });
        lsTexturesArr.put(LandscapeType.MUSHROOMS,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_mushroom_01.png", 1, 58, 53, "new/tl_mushroom_base.png", 38, 15),
                        new LsTextureDef("new/tl_mushroom_02.png", 1, 46, 83, "new/tl_mushroom_base.png", 38, 15),
                        new LsTextureDef("new/tl_mushroom_03.png", 1, 40, 90, "new/tl_mushroom_base.png", 38, 15),
                });
        lsTexturesArr.put(LandscapeType.ROCKS_MAGICLAND,
                new LsTextureDef[]{
                        new LsTextureDef("new/tl_rock_magicland_1.png", 1, 36, 50, "base_mountains.png", 47, 20),
                        new LsTextureDef("new/tl_rock_magicland_2.png", 2, 64, 79, "base_mountains.png", 47, 20),
                        new LsTextureDef("new/tl_rock_magicland_3.png", 4, 108, 97, "base_mountains.png", 47, 20),
                });


    }

    private static ResourceManager instance;
    protected ITextureRegion mBackgroundTextureRegion;
    protected Map<LandscapeType, ITextureRegion> tileRegionsMap;
    protected Map<LandscapeType, List<LsTextureDef>> landScapeTextureRegions;
    protected ITextureRegion resourcePoolsRegion;
    private TextureManager textureManager;
    private ITiledTextureRegion heroMovingRegion;
    private ITextureRegion magicTileTextureRegion;
    private ITextureRegion particleRegion;
    private ITextureRegion goldParticleRegion;
    private ITextureRegion goldCoinParticleRegion;
    private ITextureRegion symbolGoRegion;
    private ITextureRegion progressBarFrameRegion;
    private ITextureRegion progressBarLineRegion;
    private ITextureRegion concertNoteEmptyRegion;
    private ITextureRegion concertNoteGoldRegion;
    private ITextureRegion levelCompletedBgTextureRegion;
    private ITextureRegion levelFailedBgTextureRegion;
    private ITextureRegion symbolX2;
    private ITextureRegion symbolX3;
    private ITextureRegion castleCrystalFrontRegion;
    private ITextureRegion castleCrystalBackRegion;
    private Map<Integer, ITextureRegion[]> castlesBySetMap;
    private Font mFont;
    private ITextureRegion redParticleRegion;
    private Sound mySound;
    private Map<AbilityTileSprite.AbilityType, ITextureRegion> abilityTileTextureRegion = new HashMap<AbilityTileSprite.AbilityType, ITextureRegion>();
    private Font bigFont;
    private ITextureRegion cloudTextureRegion;
    private ITextureRegion cloudShTextureRegion;
    private ITiledTextureRegion hasteArrowRegion;
    private ITiledTextureRegion enemyImpRegion;
    private ITiledTextureRegion fireOnTileRegion;
    private ITiledTextureRegion manaFillingRegion;
    private ITiledTextureRegion manaSymbolRegion;
    private ITiledTextureRegion pointsSymbolRegion;
    private ITiledTextureRegion buttonTryAgainPressedTextureRegion;
    private ITiledTextureRegion buttonContinuePressedTextureRegion;
    private ITiledTextureRegion buttonClosedPressedTextureRegion;
    private Font fontTrebuchetBoldGold;
    private FontManager fontManager;
    private ITiledTextureRegion cristalBigRegion;
    private ITiledTextureRegion buttonHelpRegion;
    private ITiledTextureRegion buttonMenuRegion;
    private ITextureRegion tutorialBgRegion;
    private Map<GameTutorial.TutorialSection, ITextureRegion> tutorialSectionsRegions;
    private ITiledTextureRegion buttonNextRegion;
    private ITiledTextureRegion buttonPrevRegion;
    private ITiledTextureRegion buttonCloseTextureRegion;
    private Font fontTrebuchetBoldTutorialPaging;
    private ITiledTextureRegion[] heroIdleAnimations;
    private ITiledTextureRegion heroShootingAnimation;
    private ITextureRegion missileRegion;
    private ITiledTextureRegion heroConcertAnimation;
    private ITiledTextureRegion particlesConcert;
    private ITiledTextureRegion particlesSmoke;
    private ITiledTextureRegion particlesFlame;
    private ITextureRegion noMovesLeftMessage;
    private ITiledTextureRegion particlesSpark;
    private ITiledTextureRegion particlesGoldenStars;
    private ITextureRegion effectSkill;
    private ITextureRegion effectExplosion;
    private ITextureRegion tipArrow;
    private ITextureRegion tipShadow;
    private ITextureRegion[] townJewels;
    private ITextureRegion jewelParticle;
    private ITextureRegion[] frameJewels;
    private ITextureRegion resourcePoolsRegion2;
    private ITextureRegion impFinger;
    private ITiledTextureRegion buttonDonate;
    private ITiledTextureRegion buttonKillAds;
    private ITiledTextureRegion buttonRateApp;
    private ITiledTextureRegion movesLeft;
    private ITextureRegion manaRedBg;
    private ITextureRegion symbolEarthquake;
    private ITextureRegion symbolBigCrystal;

    public static Map<LandscapeType, LsTextureDef[]> getLsTexturesArr() {
        return lsTexturesArr;
    }

    public static ResourceManager getInstance() {
        if (instance == null) {
            instance = new ResourceManager();
        }
        return instance;
    }

    private TextureManager getTextureManager() {
        return textureManager;
    }

    private FontManager getFontManager() {
        return fontManager;
    }

    public void loadResources(TextureManager textureManager, FontManager fontManager, SoundManager soundManager, VertexBufferObjectManager vertexBufferObjectManager, Context context) throws IOException {
        this.textureManager = textureManager;
        this.fontManager = fontManager;

        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
        /*背景*/
        String bgPath = "mainscreen/game_bg.png";
        mAllTextures = new LinkedList<Texture>();
        mAllTextureNames = new LinkedList<String>();
        this.mBackgroundTextureRegion = load(bgPath, 480, 800, context);

        //Board tiles texture regions
        tileRegionsMap = new HashMap<LandscapeType, ITextureRegion>();
        loadTileRegion(LandscapeType.TOWN, "tiles/tile_town.png", 100, 110, context);
        loadTileRegion(LandscapeType.DARK_FOREST, "tiles/tile_darkforest.png", 100, 110, context);
        loadTileRegion(LandscapeType.DEAD_FOREST, "tiles/tile_deadtrees.png", 100, 110, context);
        loadTileRegion(LandscapeType.DEAD_FOREST_MAGICLAND, "tiles/tile_trees_magicland.png", 100, 110, context);
        loadTileRegion(LandscapeType.GRAIN, "tiles/tile_field.png", 100, 110, context);
        loadTileRegion(LandscapeType.BUSHES, "tiles/tile_bushes.png", 100, 110, context);
        loadTileRegion(LandscapeType.ROCK, "tile_04_rock-1.png", 100, 118, context);
        loadTileRegion(LandscapeType.HILLS, "tile_05_hill-1.png", 100, 118, context);
        loadTileRegion(LandscapeType.BLOSSOM_HILLS, "tiles/tile_blossom_hills.png", 100, 110, context);
        loadTileRegion(LandscapeType.BLOSSOM_HILLS_MAGICLAND, "tiles/tile_hills_magicland.png", 100, 110, context);
        loadTileRegion(LandscapeType.APPLE_TREES, "tiles/tile_apple_trees.png", 100, 110, context);
        loadTileRegion(LandscapeType.VILLAGE, "tiles/tile_village.png", 100, 110, context);
        loadTileRegion(LandscapeType.VILLAGE_GREY, "tiles/tile_village_gray.png", 100, 110, context);
        loadTileRegion(LandscapeType.PUMPKIN, "tiles/tile_pumpkins.png", 100, 110, context);
        loadTileRegion(LandscapeType.FORESTVILLAGE, "tiles/tile_forestvillage.png", 100, 110, context);
        loadTileRegion(LandscapeType.CASTLE, "tiles/tile_castle.png", 100, 110, context);
        loadTileRegion(LandscapeType.OAKS, "tiles/tile_oaks.png", 100, 110, context);
        loadTileRegion(LandscapeType.CEMETERY, "tiles/tile_cemetery.png", 100, 110, context);
        loadTileRegion(LandscapeType.JACKOLANTERN, "tiles/tile_jackolantern.png", 100, 110, context);
        loadTileRegion(LandscapeType.RUINS, "tiles/tile_ruins.png", 100, 110, context);
        loadTileRegion(LandscapeType.LAVA, "tiles/tile_lava.png", 100, 110, context);
        loadTileRegion(LandscapeType.IDOL, "tiles/tile_idol.png", 100, 110, context);
        loadTileRegion(LandscapeType.TOWN_LAVA, "tiles/tile_town_lava.png", 100, 110, context);
        loadTileRegion(LandscapeType.DEAD_FOREST_LAVA, "tiles/tile_deadtrees_lava.png", 100, 110, context);
        loadTileRegion(LandscapeType.DARK_ROCKS, "tiles/tile_darkrocks.png", 100, 110, context);
        loadTileRegion(LandscapeType.CRATER, "tiles/tile_crater.png", 100, 110, context);
        loadTileRegion(LandscapeType.TOWN_BLUE, "tiles/tile_town_blue.png", 100, 110, context);
        loadTileRegion(LandscapeType.WATER, "water_spritemap-2.png", 600, 590, context, true, 6, 5);
        loadTileRegion(LandscapeType.WATER_GREEN, "tiles/water_horror_spritemap.png", 600, 590, context, true, 6, 5);
        loadTileRegion(LandscapeType.BUSHES_SWAMP, "tiles/tile_bushes_swamp.png", 100, 110, context);
        loadTileRegion(LandscapeType.VILLAGE_SWAMP, "tiles/tile_village_swamp.png", 100, 110, context);
        loadTileRegion(LandscapeType.DEAD_FOREST_SWAMP, "tiles/tile_deadtrees_swamp.png", 100, 110, context);
        loadTileRegion(LandscapeType.ROCKS_SWAMP, "tiles/tile_rocks_swamp.png", 100, 110, context);
        loadTileRegion(LandscapeType.LILLY, "tiles/tile_lilly.png", 100, 110, context);
        loadTileRegion(LandscapeType.IDOL_MAGICLAND, "tiles/tile_idol_magicland.png", 100, 110, context);
        loadTileRegion(LandscapeType.MUSHROOMS, "tiles/tile_mushrooms.png", 100, 110, context);
        loadTileRegion(LandscapeType.ROCKS_MAGICLAND, "tiles/tile_rocks_magicland.png", 100, 110, context);
        loadTileRegion(LandscapeType.TOWN_MAGICLAND, "tiles/tile_town_magicland.png", 100, 110, context);
        loadTileRegion(LandscapeType.CANE, "tiles/tile_cane.png", 100, 110, context);


        magicTileTextureRegion = loadTiled("cristal_small_spritemap.png", 413, 310, 7, 5, context);


        ITiledTextureRegion abilityRegions = loadTiled("tiles/skill_icons.png", 370, 66, 5, 1, context);
        abilityTileTextureRegion.put(AbilityTileSprite.AbilityType.MOVE_HERO, abilityRegions.getTextureRegion(0));
        abilityTileTextureRegion.put(AbilityTileSprite.AbilityType.MISSILE, abilityRegions.getTextureRegion(1));
        abilityTileTextureRegion.put(AbilityTileSprite.AbilityType.EXPLODE_9, abilityRegions.getTextureRegion(2));
        abilityTileTextureRegion.put(AbilityTileSprite.AbilityType.COLLECT_CRYSTALS, abilityRegions.getTextureRegion(3));
        abilityTileTextureRegion.put(AbilityTileSprite.AbilityType.PLAY_CONCERT, abilityRegions.getTextureRegion(4));

//        abilityTileTextureRegion.put(AbilityTileSprite.AbilityType.PLAY_CONCERT, load("tiles/tile_fame.png", 73,73,context));

        this.landScapeTextureRegions = new HashMap<LandscapeType, List<LsTextureDef>>();
        for (LandscapeType lsType : lsTexturesArr.keySet()) {
            LsTextureDef[] textureArr = lsTexturesArr.get(lsType);
            if (LevelDefinition.getLevels()[GameProfile.selectedLevelAreaIndex].lsTypesBoard.contains(lsType)
                    || LevelDefinition.getLevels()[GameProfile.selectedLevelAreaIndex].lsTypesTimeline.contains(lsType)) {
                List<LsTextureDef> lsRegions = new ArrayList<LsTextureDef>();
                for (LsTextureDef textureDef : textureArr) {
                    if (textureDef.getTextureFilename() != null) {
                        textureDef.setTextureRegion(load("timeline/" + textureDef.getTextureFilename(), textureDef.getWidth(), textureDef.getHeight(), context));
                    }
                    lsRegions.add(textureDef);
                    textureDef.setBaseTextureRegion(load("timeline/" + textureDef.getBaseTextureFilename(), textureDef.getBaseWidth(), textureDef.getBaseHeight(), context));
                }
                landScapeTextureRegions.put(lsType, lsRegions);
            }
        }

        heroMovingRegion = loadTiled("go_anim_2.png", 1500, 62, 25, 1, context);
        particleRegion = load("particle.png", 25, 25, context);
        goldParticleRegion = load("particle_gold.png", 25, 25, context);
        redParticleRegion = load("particle_red.png", 25, 25, context);
        goldCoinParticleRegion = load("effects/particle_gold_coin.png", 41, 41, context);

        fireOnTileRegion = loadTiled("fire_spritemap.png", 252, 36, 9, 1, context, false, false, true);
        hasteArrowRegion = loadTiled("haste_spritemap.png", 336, 25, 8, 1, context);
        enemyImpRegion = loadTiled("timeline/mob_imp_spritemap.png", 1311, 67, 19, 1, context);
        cloudTextureRegion = load("cloud/cloud.png", 146, 79, context);
        cloudShTextureRegion = load("cloud/cloud_shadow.png", 142, 58, context);
        symbolGoRegion = load("effects/symbol_go.png", 57, 57, context);
        resourcePoolsRegion = load("mainscreen/game_frame.png", 480, 800, context);
        resourcePoolsRegion2 = load("mainscreen/game_frame_top.png", 480, 800, context);
        manaFillingRegion = loadTiled("effects/mana_pool_spritemap.png", 1000, 1000, 10, 10, context);
        manaSymbolRegion = loadTiled("effects/symbols_mana_income.png", 602, 77, 7, 1, context);
        pointsSymbolRegion = loadTiled("effects/symbols_gold_income.png", 558, 52, 6, 1, context);
        concertNoteEmptyRegion = load("timeline/note_empty.png", 30, 41, context);
        concertNoteGoldRegion = load("timeline/note_golden.png", 30, 41, context, false, false, true);

        levelCompletedBgTextureRegion = load("levelfinished/popup_success_bg.png", 480, 800, context, false, false, true);
        levelFailedBgTextureRegion = load("levelfinished/popup_fail_bg.png", 480, 800, context, false, false, true);

        buttonTryAgainPressedTextureRegion = loadTiled("levelfinished/btn_tryagain_pressed.png", 310, 65, 2, 1, context, false, false, true);
        buttonContinuePressedTextureRegion = loadTiled("levelfinished/btn_continue-1.png", 278, 63, 2, 1, context, false, false, true);
        buttonDonate = loadTiled("levelfinished/btn_donate.png", 278, 63, 2, 1, context, false, false, true);
        buttonKillAds = loadTiled("levelfinished/btn_kill_ads.png", 278, 63, 2, 1, context, false, false, true);
        buttonRateApp = loadTiled("levelfinished/btn_rate_app.png", 278, 63, 2, 1, context, false, false, true);
        buttonClosedPressedTextureRegion = loadTiled("levelfinished/btn_close_pressed.png", 110, 55, 2, 1, context);

        symbolX2 = load("effects/symbol_x2.png", 57, 57, context);
        symbolX3 = load("effects/symbol_x3.png", 57, 57, context);

        castleCrystalBackRegion = load("castle/tl_cristal.png", 160, 180, context);
        castleCrystalFrontRegion = load("castle/tl_cristal_base.png", 160, 180, context);

        castlesBySetMap = new HashMap<Integer, ITextureRegion[]>();
        if (GameProfile.selectedLevelAreaIndex == 0 || GameProfile.selectedLevelAreaIndex == 1) {
            ITextureRegion[] castlesForSet1 = new ITextureRegion[4];
            castlesForSet1[0] = load("castle/tl_start_hometown.png", 160, 180, context);
            castlesForSet1[1] = load("castle/tl_start_hometown_base.png", 160, 180, context);
            castlesForSet1[2] = load("castle/tl_finish_farmland.png", 160, 180, context, false, false, true);
            castlesForSet1[3] = load("castle/tl_finish_farmland_base.png", 160, 180, context, false, false, true);
            castlesBySetMap.put(0, castlesForSet1);
            ITextureRegion[] castlesForSetm1 = new ITextureRegion[4];
            castlesForSetm1[2] = load("castle/tl_finish_hometown.png", 160, 180, context, false, false, true);
            castlesForSetm1[3] = load("castle/tl_finish_hometown_base.png", 160, 180, context, false, false, true);
            castlesBySetMap.put(-1, castlesForSetm1);
        }

        if (GameProfile.selectedLevelAreaIndex == 1 || GameProfile.selectedLevelAreaIndex == 2) {
            ITextureRegion[] castlesForSet2 = new ITextureRegion[4];
            castlesForSet2[0] = load("castle/tl_start_farmland.png", 160, 180, context);
            castlesForSet2[1] = load("castle/tl_start_farmland_base.png", 160, 180, context);
            castlesForSet2[2] = load("castle/tl_finish_castle.png", 160, 180, context, false, false, true);
            castlesForSet2[3] = load("castle/tl_finish_castle_base.png", 160, 180, context, false, false, true);

            castlesBySetMap.put(1, castlesForSet2);

        }

        if (GameProfile.selectedLevelAreaIndex == 2 || GameProfile.selectedLevelAreaIndex == 3) {
            ITextureRegion[] castlesForSet3 = new ITextureRegion[4];
            castlesForSet3[0] = load("castle/tl_start_castle.png", 160, 180, context);
            castlesForSet3[1] = load("castle/tl_start_castle_base.png", 160, 180, context);
            castlesForSet3[2] = load("castle/tl_finish_treehouse_base.png", 160, 180, context, false, false, true);
            castlesForSet3[3] = load("castle/tl_finish_treehouse_base.png", 160, 180, context, false, false, true);

            castlesBySetMap.put(2, castlesForSet3);

        }

        if (GameProfile.selectedLevelAreaIndex == 3 || GameProfile.selectedLevelAreaIndex == 4) {
            ITextureRegion[] castlesForSet4 = new ITextureRegion[4];
            castlesForSet4[0] = load("castle/tl_start_treehouse_base.png", 160, 180, context);
            castlesForSet4[1] = load("castle/tl_start_treehouse_base.png", 160, 180, context);
            castlesForSet4[2] = load("castle/tl_finish_horror.png", 160, 180, context, false, false, true);
            castlesForSet4[3] = load("castle/tl_finish_horror_base.png", 160, 180, context, false, false, true);

            castlesBySetMap.put(3, castlesForSet4);
        }

        if (GameProfile.selectedLevelAreaIndex == 4 || GameProfile.selectedLevelAreaIndex == 5) {

            ITextureRegion[] castlesForSet5 = new ITextureRegion[4];
            castlesForSet5[0] = load("castle/tl_start_horror.png", 160, 180, context);
            castlesForSet5[1] = load("castle/tl_start_horror_base.png", 160, 180, context);
            castlesForSet5[2] = load("castle/tl_finish_volcano.png", 160, 180, context, false, false, true);
            castlesForSet5[3] = load("castle/tl_finish_volcano_base.png", 160, 180, context, false, false, true);

            castlesBySetMap.put(4, castlesForSet5);
        }

        if (GameProfile.selectedLevelAreaIndex == 5 || GameProfile.selectedLevelAreaIndex == 6) {

            ITextureRegion[] castlesForSet6 = new ITextureRegion[4];
            castlesForSet6[0] = load("castle/tl_start_volcano.png", 160, 180, context);
            castlesForSet6[1] = load("castle/tl_start_volcano_base.png", 160, 180, context);
            castlesForSet6[2] = load("castle/tl_finish_swamp.png", 160, 180, context, false, false, true);
            castlesForSet6[3] = load("castle/tl_finish_swamp_base.png", 160, 180, context, false, false, true);

            castlesBySetMap.put(5, castlesForSet6);

        }

        if (GameProfile.selectedLevelAreaIndex == 6 || GameProfile.selectedLevelAreaIndex == 7) {
            ITextureRegion[] castlesForSet7 = new ITextureRegion[4];
            castlesForSet7[0] = load("castle/tl_start_swamp.png", 160, 180, context);
            castlesForSet7[1] = load("castle/tl_start_swamp_base.png", 160, 180, context);
            castlesForSet7[2] = load("castle/tl_finish_magicland.png", 141, 170, context, false, false, true);
            castlesForSet7[3] = load("castle/tl_finish_magicland_base.png", 140, 16, context, false, false, true);

            castlesBySetMap.put(6, castlesForSet7);

        }

        if (GameProfile.selectedLevelAreaIndex == 7 || GameProfile.selectedLevelAreaIndex == 8) {
            ITextureRegion[] castlesForSet8 = new ITextureRegion[4];
            castlesForSet8[0] = load("castle/tl_start_magicland.png", 131, 170, context);
            castlesForSet8[1] = load("castle/tl_start_magicland_base.png", 131, 16, context);
            castlesForSet8[2] = load("castle/tl_finish_final.png", 279, 180, context, false, false, true);
            //castlesForSet8[3] = load("castle/tl_finish_magicland_base.png", 140, 16, context, false, false, true);


            castlesBySetMap.put(7, castlesForSet8);
        }

        if (GameProfile.selectedLevelAreaIndex == 8 || GameProfile.selectedLevelAreaIndex == 9) {
            ITextureRegion[] castlesForSet8 = new ITextureRegion[4];
            castlesForSet8[0] = load("castle/tl_start_magicland.png", 131, 170, context);
            castlesForSet8[1] = load("castle/tl_start_magicland_base.png", 131, 16, context);
            castlesForSet8[2] = load("castle/tl_finish_final.png", 279, 180, context, false, false, true);
            //castlesForSet8[3] = load("castle/tl_finish_magicland_base.png", 140, 16, context, false, false, true);
            castlesBySetMap.put(8, castlesForSet8);
        }

        cristalBigRegion = loadTiled("cristal_big_spritemap.png", 814, 198, 11, 3, context);

        progressBarFrameRegion = load("progressbar/progressbar_frame.png", 480, 227, context);
        progressBarLineRegion = load("progressbar/progressbar_fill.png", 480, 227, context);

        buttonHelpRegion = loadTiled("mainscreen/btn_help.png", 122, 62, 2, 1, context);
        buttonMenuRegion = loadTiled("mainscreen/btn_menu.png", 122, 62, 2, 1, context);


        buttonCloseTextureRegion = loadTiled("common/btn_x.png", 110, 55, 2, 1, context);

        heroIdleAnimations = new ITiledTextureRegion[4];
        heroIdleAnimations[0] = loadTiled("hero/idle_anim_01.png", 1425, 62, 19, 1, context);
        heroIdleAnimations[1] = loadTiled("hero/idle_anim_02.png", 450, 186, 6, 3, context);
        heroIdleAnimations[2] = loadTiled("hero/idle_anim_03.png", 300, 186, 4, 3, context);
        heroIdleAnimations[3] = loadTiled("hero/idle_anim_04.png", 300, 248, 4, 4, context);
        heroShootingAnimation = loadTiled("hero/shot_anim.png", 850, 310, 10, 5, context);
        heroConcertAnimation = loadTiled("hero/concert_anim.png", 700, 360, 10, 5, context, false, false, true);
        missileRegion = load("hero/missile.png", 80, 48, context);

        particlesConcert = loadTiled("effects/particle_concert.png", 60, 30, 2, 1, context, false, false, true);
        particlesSmoke = loadTiled("effects/particle_smoke.png", 90, 30, 3, 1, context);
        particlesFlame = loadTiled("effects/particle_flames.png", 90, 30, 3, 1, context);
        particlesSpark = loadTiled("effects/particle_spark.png", 60, 60, 2, 2, context);
        particlesGoldenStars = loadTiled("effects/particle_golden_stars.png", 145, 30, 5, 1, context);
        noMovesLeftMessage = load("mainscreen/no_moves_left.png", 480, 800, context);

        effectSkill = load("effects/skill_effect.png", 194, 194, context);
        effectExplosion = load("effects/explosion.png", 140, 140, context);

        tipArrow = load("effects/tip_arrow.png", 31, 33, context);
        tipShadow = load("effects/tip_shadow.png", 100, 110, context);

        townJewels = new ITextureRegion[3];
        townJewels[0] = load("timeline/town_jewels_1.png", 181, 83, context);
        townJewels[1] = load("timeline/town_jewels_2.png", 181, 83, context);
        townJewels[2] = load("timeline/town_jewels_3.png", 181, 83, context);

        jewelParticle = load("timeline/jewel_particle.png", 25, 24, context);
        impFinger = load("levelfinished/imp_finger.png", 39, 49, context);

        frameJewels = new ITextureRegion[5];
        frameJewels[0] = load("timeline/jewel_1.png", 480, 59, context);
        frameJewels[1] = load("timeline/jewel_2.png", 480, 59, context);
        frameJewels[2] = load("timeline/jewel_3.png", 480, 59, context);
        frameJewels[3] = load("timeline/jewel_4.png", 480, 59, context);
        frameJewels[4] = load("timeline/jewel_5.png", 480, 59, context);

        movesLeft = loadTiled("effects/moves_left.png", 565, 113, 5, 1, context);
        manaRedBg = load("effects/magic_pool_red.png", 122, 124, context);

        symbolBigCrystal = load("effects/symbol_big_crystal.png", 170, 110, context);
        symbolEarthquake = load("effects/symbol_earthquake.png", 419, 165, context);

        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("fonts/");
        BitmapTextureAtlas mFontTexture = new BitmapTextureAtlas(getTextureManager(), 256, 256, TextureOptions.DEFAULT);
        BitmapTextureAtlas bigFontTexture = new BitmapTextureAtlas(getTextureManager(), 256, 256, TextureOptions.DEFAULT);
        BitmapTextureAtlas fontTrebuchetTexture = new BitmapTextureAtlas(getTextureManager(), 256, 256, TextureOptions.DEFAULT);
        BitmapTextureAtlas fontTrebuchetPagingTexture = new BitmapTextureAtlas(getTextureManager(), 256, 256, TextureOptions.DEFAULT);
        this.mFont = FontFactory.createFromAsset(getFontManager(), mFontTexture, context.getAssets(), "fonts/Trebuchet_MS.ttf", 14, true, Color.WHITE);
        this.bigFont = FontFactory.createFromAsset(getFontManager(), bigFontTexture, context.getAssets(), "fonts/Trebuchet_MS.ttf", 25, true, Color.WHITE);
        this.fontTrebuchetBoldGold = FontFactory.createFromAsset(getFontManager(), fontTrebuchetTexture, context.getAssets(), "fonts/Trebuchet_MS_bold.ttf", 25, true, Color.rgb(243, 180, 58));
        this.fontTrebuchetBoldTutorialPaging = FontFactory.createFromAsset(getFontManager(), fontTrebuchetPagingTexture, context.getAssets(), "fonts/Trebuchet_MS_bold.ttf", 22, true, Color.rgb(160, 136, 113));
        this.getTextureManager().loadTexture(mFontTexture);
        this.getTextureManager().loadTexture(bigFontTexture);
        this.getTextureManager().loadTexture(fontTrebuchetTexture);
        this.getTextureManager().loadTexture(fontTrebuchetPagingTexture);
        this.getFontManager().loadFont(this.mFont);
        this.getFontManager().loadFont(this.bigFont);
        this.getFontManager().loadFont(this.fontTrebuchetBoldGold);
        this.getFontManager().loadFont(this.fontTrebuchetBoldTutorialPaging);


        //SoundFactory.setAssetBasePath("raw/");
        //this.mySound = SoundFactory.createSoundFromAsset(soundManager, context, "raw/myfirstwav.ogg");
    }

    private void loadTileRegion(LandscapeType lsType, String s, int w, int h, Context context, boolean tiled, int rows, int cols) {
        if (LevelDefinition.getLevels()[GameProfile.selectedLevelAreaIndex].lsTypesBoard.contains(lsType)
                || LevelDefinition.getLevels()[GameProfile.selectedLevelAreaIndex].lsTypesTimeline.contains(lsType)) {
            if (tiled) {
                tileRegionsMap.put(lsType, loadTiled(s, w, h, rows, cols, context));
            } else {
                tileRegionsMap.put(lsType, load(s, w, h, context));
            }
        }
    }

    private void loadTileRegion(LandscapeType town, String s, int w, int h, Context context) {
        loadTileRegion(town, s, w, h, context, false, 0, 0);
    }

    public void loadTutorialGfx(Context context) {
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
        tutorialBgRegion = load("tutorial/tutorials_bg.png", 480, 800, context, false, true);
        tutorialSectionsRegions = new HashMap<GameTutorial.TutorialSection, ITextureRegion>();
        buttonNextRegion = loadTiled("tutorial/btn_next.png", 162, 65, 2, 1, context, false, true, false);
        buttonPrevRegion = loadTiled("tutorial/btn_prev.png", 162, 65, 2, 1, context, false, true, false);
    }

    private ITiledTextureRegion loadTiled(String filename, int w, int h, int col, int row, Context context) {
        return loadTiled(filename, w, h, col, row, context, true, false, false);
    }

    private ITiledTextureRegion loadTiled(String filename, int w, int h, int col, int row, Context context, boolean toPreload, boolean toLoad, boolean loadAfter) {
        BitmapTextureAtlas texture = new BitmapTextureAtlas(getTextureManager(), w, h, TextureOptions.BILINEAR);
        ITiledTextureRegion region = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(texture, context, filename, 0, 0, col, row);
        if (toPreload) {
            mAllTextures.add(texture);
            mAllTextureNames.add(filename);
        } else if (loadAfter) {
            //deactivated after load temporarily - needs to be reconsidered
            mAllTextures.add(texture);
            mAllTextureNames.add(filename);
            //afterLoadTextures.add(texture);
            //afterLoadTextureNames.add(filename);
        } else if (toLoad) {
            texture.load();
        }
        return region;
    }

    private ITextureRegion load(String filename, int w, int h, Context context, boolean toPreload, boolean toLoad) {
        return load(filename, w, h, context, toPreload, toLoad, false);
    }

    private ITextureRegion load(String filename, int w, int h, Context context, boolean toPreload, boolean toLoad, boolean loadAfter) {
        BitmapTextureAtlas texture = new BitmapTextureAtlas(getTextureManager(), w, h, TextureOptions.BILINEAR);
        ITextureRegion region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(texture, context, filename, 0, 0);
        if (toPreload) {
            mAllTextures.add(texture);
            mAllTextureNames.add(filename);
        } else if (loadAfter) {
            //deactivated after load temporarily - needs to be reconsidered
            mAllTextures.add(texture);
            mAllTextureNames.add(filename);

//            afterLoadTextures.add(texture);
//            afterLoadTextureNames.add(filename);
        } else if (toLoad) {
            texture.load();
        }
        return region;
    }

    private ITextureRegion load(String filename, int w, int h, Context context) {
        return load(filename, w, h, context, true, false);
    }

    public Sound getMySound() {
        return mySound;
    }

    public void setMySound(Sound mySound) {
        this.mySound = mySound;
    }

    public ITextureRegion getBackgroundTextureRegion() {
        return mBackgroundTextureRegion;
    }

    public ITextureRegion getTileTextureRegion(LandscapeType lsType) {
        return tileRegionsMap.get(lsType);
    }

    public ITiledTextureRegion getHeroMovingRegion() {
        return heroMovingRegion;
    }

    public Font getmFont() {
        return mFont;
    }

    public LsTextureDef getRandomLandScapeForStyle(LandscapeType landscapeType) {
        List<LsTextureDef> lsTextureDefs = landScapeTextureRegions.get(landscapeType);
        int select = MathUtils.random(0, lsTextureDefs.size() - 1);
        return lsTextureDefs.get(select);
    }

    public LsTextureDef getLandScapeForStyleByIndex(LandscapeType landscapeType, int lsIndex) {
        List<LsTextureDef> lsTextureDefs = landScapeTextureRegions.get(landscapeType);
        LOG.i("lstype = " + landscapeType.name() + " " + lsIndex);
        return lsTextureDefs.get(lsIndex);
    }


    public LsTextureDef getMaxLandScapeForStyle(LandscapeType landscapeType, int remainSteps) {
        List<LsTextureDef> lsTextureDefs = landScapeTextureRegions.get(landscapeType);
        Map<Integer, List<LsTextureDef>> texturesBySize = new HashMap<Integer, List<LsTextureDef>>();
        List<Integer> keyList = new LinkedList<Integer>();
        for (LsTextureDef ls : lsTextureDefs) {
            int steps = ls.getSteps();
            List<LsTextureDef> listForSteps = texturesBySize.get(steps);
            if (listForSteps == null) {
                listForSteps = new LinkedList<LsTextureDef>();
                texturesBySize.put(steps, listForSteps);
                keyList.add(steps);
            }
            listForSteps.add(ls);
        }
        //LOG.d("Retrieving maxLandscape for style " + landscapeType + ", remainSteps = " + remainSteps + ", stepKeys = " + keyList);
        int stepKeyIndex = keyList.size();
        List<LsTextureDef> listForSteps = null;
        do {
            stepKeyIndex--;
            listForSteps = texturesBySize.get(keyList.get(stepKeyIndex));
        } while (keyList.get(stepKeyIndex) > remainSteps);
        //LOG.d("Found max step length - " + keyList.get(stepKeyIndex));
        int select = MathUtils.random(0, listForSteps.size() - 1);
        return listForSteps.get(select);
    }

    public ITextureRegion getMagicTileTextureRegion() {
        return magicTileTextureRegion;
    }

    public ITextureRegion getParticleRegion() {
        return particleRegion;
    }

    public ITextureRegion getAbilityTileTextureRegion(AbilityTileSprite.AbilityType abilityType) {
        return abilityTileTextureRegion.get(abilityType);
    }

    public Font getBigFont() {
        return bigFont;
    }

    public ITextureRegion getCloudTextureRegion() {
        return cloudTextureRegion;
    }

    public ITextureRegion getCloudShTextureRegion() {
        return cloudShTextureRegion;
    }

    public ITiledTextureRegion getHasteArrowRegion() {
        return hasteArrowRegion;
    }

    public ITiledTextureRegion getFireOnTileRegion() {
        return fireOnTileRegion;
    }

    public ITiledTextureRegion getEnemyImpRegion() {
        return enemyImpRegion;
    }

    public ITextureRegion getGoldParticleRegion() {
        return goldParticleRegion;
    }

    public ITextureRegion getSymbolGoRegion() {
        return symbolGoRegion;
    }

    public ITextureRegion getProgressBarFrameRegion() {
        return progressBarFrameRegion;
    }

    public ITextureRegion getProgressBarLineRegion() {
        return progressBarLineRegion;
    }

    public ITextureRegion getResourcePoolsRegion() {
        return resourcePoolsRegion;
    }

    public ITextureRegion getGoldCoinParticleRegion() {
        return goldCoinParticleRegion;
    }

    public ITiledTextureRegion getManaFillingRegion() {
        return manaFillingRegion;
    }

    public ITextureRegion getConcertNoteEmptyRegion() {
        return concertNoteEmptyRegion;
    }

    public ITextureRegion getConcertNoteGoldRegion() {
        return concertNoteGoldRegion;
    }

    public ITiledTextureRegion getManaSymbolRegion() {
        return manaSymbolRegion;
    }

    public ITiledTextureRegion getPointsSymbolRegion() {
        return pointsSymbolRegion;
    }

    public ITextureRegion getLevelCompletedBgTextureRegion() {
        return levelCompletedBgTextureRegion;
    }

    public ITextureRegion getLevelFailedBgTextureRegion() {
        return levelFailedBgTextureRegion;
    }

    public ITiledTextureRegion getButtonTryAgainPressedTextureRegion() {
        return buttonTryAgainPressedTextureRegion;
    }

    public ITiledTextureRegion getButtonContinuePressedTextureRegion() {
        return buttonContinuePressedTextureRegion;
    }

    public ITiledTextureRegion getButtonClosedPressedTextureRegion() {
        return buttonClosedPressedTextureRegion;
    }

    public IFont getFontTrebuchetBoldGold() {
        return fontTrebuchetBoldGold;
    }

    public ITextureRegion getSymbolX2() {
        return symbolX2;
    }

    public ITextureRegion getSymbolX3() {
        return symbolX3;
    }

    public Map<Integer, ITextureRegion[]> getCastlesBySetMap() {
        return castlesBySetMap;
    }

    public ITextureRegion getCastleCrystalBackRegion() {
        return castleCrystalBackRegion;
    }

    public ITextureRegion getCastleCrystalFrontRegion() {
        return castleCrystalFrontRegion;
    }

    public ITextureRegion getRedParticleRegion() {
        return redParticleRegion;
    }

    public ITiledTextureRegion getCristalBigRegion() {
        return cristalBigRegion;
    }

    public ITiledTextureRegion getButtonHelpRegion() {
        return buttonHelpRegion;
    }

    public ITiledTextureRegion getButtonMenuRegion() {
        return buttonMenuRegion;
    }

    public ITextureRegion getTutorialBgRegion() {
        return tutorialBgRegion;
    }

    public ITiledTextureRegion getButtonPrevRegion() {
        return buttonPrevRegion;
    }

    public ITiledTextureRegion getButtonNextRegion() {
        return buttonNextRegion;
    }

    public ITextureRegion getTutorialSectionsRegion(GameTutorial.TutorialSection section, Context context) {
        if (tutorialSectionsRegions.get(section) != null) {
            return tutorialSectionsRegions.get(section);
        }
        switch (section) {
            case TUTORIAL_MAIN_GOAL:
                tutorialSectionsRegions.put(GameTutorial.TutorialSection.TUTORIAL_MAIN_GOAL, load("tutorial/tutorials_01.png", 480, 800, context, false, true));
                break;
            case TUTORIAL_CRYSTAL_TILE:
                tutorialSectionsRegions.put(GameTutorial.TutorialSection.TUTORIAL_CRYSTAL_TILE, load("tutorial/tutorials_02.png", 480, 800, context, false, true));
                break;
            case TUTORIAL_ABILITIES_MOVEHERO_CONCERT:
                tutorialSectionsRegions.put(GameTutorial.TutorialSection.TUTORIAL_ABILITIES_MOVEHERO_CONCERT, load("tutorial/tutorials_03.png", 480, 800, context, false, true));
                break;
            case TUTORIAL_ABILITIES_EXPLODE9_COLLECT:
                tutorialSectionsRegions.put(GameTutorial.TutorialSection.TUTORIAL_ABILITIES_EXPLODE9_COLLECT, load("tutorial/tutorials_04.png", 480, 800, context, false, true));
                break;
            case TUTORIAL_ABILITY_TILE_MISSILE:
                tutorialSectionsRegions.put(GameTutorial.TutorialSection.TUTORIAL_ABILITY_TILE_MISSILE, load("tutorial/tutorials_05.png", 480, 800, context, false, true));
                break;
        }
        return tutorialSectionsRegions.get(section);
    }

    public ITiledTextureRegion getButtonCloseTextureRegion() {
        return buttonCloseTextureRegion;
    }

    public IFont getFontTrebuchetBoldTutorialPaging() {
        return fontTrebuchetBoldTutorialPaging;
    }

    public ITiledTextureRegion[] getHeroIdleAnimations() {
        return heroIdleAnimations;
    }

    public ITiledTextureRegion getHeroShootingAnimation() {
        return heroShootingAnimation;
    }

    public ITextureRegion getMissileRegion() {
        return missileRegion;
    }

    public ITiledTextureRegion getHeroConcertAnimation() {
        return heroConcertAnimation;
    }

    public ITiledTextureRegion getParticlesConcert() {
        return particlesConcert;
    }

    public ITiledTextureRegion getParticlesSmoke() {
        return particlesSmoke;
    }

    public ITiledTextureRegion getParticlesFlame() {
        return particlesFlame;
    }

    public List<Texture> getmAllTextures() {
        return mAllTextures;
    }

    public List<String> getmAllTextureNames() {
        return mAllTextureNames;
    }

    public ITextureRegion getNoMovesLeftMessage() {
        return noMovesLeftMessage;
    }

    public ITiledTextureRegion getParticlesSpark() {
        return particlesSpark;
    }

    public ITextureRegion getEffectSkill() {
        return effectSkill;
    }

    public ITextureRegion getEffectExplosion() {
        return effectExplosion;
    }

    public List<Texture> getAfterLoadTextures() {
        return afterLoadTextures;
    }

    public List<String> getAfterLoadTextureNames() {
        return afterLoadTextureNames;
    }

    public ITextureRegion getTipArrow() {
        return tipArrow;
    }

    public ITextureRegion getTipShadow() {
        return tipShadow;
    }

    public ITextureRegion[] getTownJewels() {
        return townJewels;
    }

    public ITextureRegion[] getFrameJewels() {
        return frameJewels;
    }

    public ITextureRegion getJewelParticle() {
        return jewelParticle;
    }

    public ITextureRegion getResourcePoolsRegion2() {
        return resourcePoolsRegion2;
    }

    public ITiledTextureRegion getParticlesGoldenStars() {
        return particlesGoldenStars;
    }

    public ITextureRegion getImpFinger() {
        return impFinger;
    }

    public ITiledTextureRegion getButtonDonate() {
        return buttonDonate;
    }

    public ITiledTextureRegion getButtonKillAds() {
        return buttonKillAds;
    }

    public ITiledTextureRegion getButtonRateApp() {
        return buttonRateApp;
    }

    public ITiledTextureRegion getMovesLeft() {
        return movesLeft;
    }

    public ITextureRegion getManaRedBg() {
        return manaRedBg;
    }

    public ITextureRegion getSymbolBigCrystal() {
        return symbolBigCrystal;
    }

    public ITextureRegion getSymbolEarthquake() {
        return symbolEarthquake;
    }
}

